package es.project.sien7e.main.controllers;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;

import es.project.sien7e.main.model.Usuario;
import es.project.sien7e.main.services.DAOService;

@Controller
@RequestMapping(value = "jmesa")
public class JmesaController {
	private DAOService daoService;
	private Gson gson = new Gson();

	@Autowired
	public void setDAOService(DAOService daoService) {
		this.daoService = daoService;
	}

	@RequestMapping(value = "/usuario/grabar", method = RequestMethod.POST)
	public @ResponseBody
	String grabar(@ModelAttribute("usuario") Usuario usuario,
			HttpServletResponse response) throws Exception {
		return gson.toJson(daoService.grabaUsuario(usuario));
	}
}
